package com.ruibang.glass.material.service.impl.bhbj;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruibang.glass.material.constant.Constants;
import com.ruibang.glass.material.domain.req.ycl.ManageLocationReq;
import com.ruibang.glass.material.entity.bhbj.MaterialBHBJLocationManagement;
import com.ruibang.glass.material.entity.ycl.MaterialLocationManagement;
import com.ruibang.glass.material.mapper.bhbj.GMaterialBHBJLocationManagementMapper;
import com.ruibang.glass.material.service.bhbj.GMaterialBHBJLocationManagementService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 原材料库位管理表 服务实现类
 * </p>
 *
 * @author mameng
 * @since 2024-04-01
 */
@Service
public class GMaterialBHBJLocationManagementServiceImpl extends ServiceImpl<GMaterialBHBJLocationManagementMapper, MaterialBHBJLocationManagement> implements GMaterialBHBJLocationManagementService {

    @Override
    public IPage<MaterialBHBJLocationManagement> getPage(ManageLocationReq manageLocationReq) {
        LambdaQueryWrapper<MaterialBHBJLocationManagement> queryWrapper = Wrappers.<MaterialBHBJLocationManagement>lambdaQuery();
        if (StringUtils.isNotBlank(manageLocationReq.getLocationName())) {
            queryWrapper.like(MaterialBHBJLocationManagement::getLocationName, manageLocationReq.getLocationName());
        }
        if (StringUtils.isNotBlank(manageLocationReq.getLocationName())) {
            queryWrapper.like(MaterialBHBJLocationManagement::getLocationName, manageLocationReq.getLocationName());
        }
        if (StringUtils.isNotBlank(manageLocationReq.getStatus())) {
            queryWrapper.like(MaterialBHBJLocationManagement::getStatus, manageLocationReq.getStatus());
        }
        Page<MaterialBHBJLocationManagement> materialWarehouseInfoPage = baseMapper.selectPage(new Page<>(manageLocationReq.getPageNo(), manageLocationReq.getPageSize()),
                queryWrapper.orderByDesc(MaterialBHBJLocationManagement::getCreateTime)
        );
        return materialWarehouseInfoPage;
    }

    @Override
    public List<MaterialBHBJLocationManagement> getSelectList() {
        List<MaterialBHBJLocationManagement> materialLocationManagements = baseMapper.selectList
                (Wrappers.<MaterialBHBJLocationManagement>lambdaQuery()
                        .select(MaterialBHBJLocationManagement::getId, MaterialBHBJLocationManagement::getLocationName)
                        .eq(MaterialBHBJLocationManagement::getStatus, Constants.ONE_STR)
                );
        return materialLocationManagements;
    }
}
